app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
  /* 合同类型清单 */
  .state('contract_type', {
    url: '/contract_type',
    templateUrl: 'app/partials/contract_type/index.html',
    controller: function($scope, ContractType, $location) {
      $scope.widget_title = '合同类型管理';
      $scope.contract_types = ContractType.query();
      /* 删除 记录*/
      $scope.itemDelete = function(item){
        ContractType.delete({},{"id": $scope.contract_types[item].id})
        $scope.contract_types.splice(item, 1); 
      }

      /* 编辑*/ 
      $scope.itemEdit = function(item){
        $location.url("/contract_type/"+ item +"/edit")
      }

   }
  })
 
  /*添加岗位类型*/
  .state('contract_type.new', {
    url: '/new',
    templateUrl: 'app/partials/contract_type/form.html',
    controller: function($scope,$state,ContractType) {
      $scope.widget_title = '添加合同类型';
      $scope.update = function(contract_type){
        ContractType.save(contract_type,function(nr){
          $scope.contract_types.push(nr);
        });
        
        $scope.contract_type = {};
        $state.go('contract_type');
      }
   }
  })

  /* 编辑合同类型*/
  .state('contract_type.edit', {
    url: '/:id/edit',
    templateUrl: 'app/partials/contract_type/form.html',
    controller: function($scope,$state,ContractType, $stateParams) {
      $scope.widget_title = '编辑合同类型';
      $scope.contract_type = ContractType.get({id: $stateParams.id})
      $scope.update = function(contract_type){
        ContractType.update(contract_type)
        $state.transitionTo('contract_type',$stateParams,{reload: true});
      }
   }
  })
})